import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.PriorityQueue;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘远望
 * Date: 2025-04-30
 * Time: 19:55
 */
//函数接口，只能由一个抽象类方法
@FunctionalInterface
interface IA {
    void func();

    public static void func2(){
        System.out.println("888");
    }
    //只有一个抽象函数符合函数接口
}

//无返回值无参数

@FunctionalInterface

interface NoParameterNoReturn {
    void test();
}

//无返回值一个参数

@FunctionalInterface

interface OneParameterNoReturn {
    void test(int a);
}

//无返回值多个参数

@FunctionalInterface

interface MoreParameterNoReturn {
    void test(int a, int b);
}

//有返回值无参数

@FunctionalInterface

interface NoParameterReturn {
    int test();
}


//有返回值一个参数

@FunctionalInterface

interface OneParameterReturn {
    int test(int a);
}

//有返回值多参数

@FunctionalInterface

interface MoreParameterReturn {
    int test(int a, int b);
}

public class Test {

    public static void main(String[] args) {
        HashMap<String, Integer> hashMap = new HashMap<>();
        hashMap.put("hello", 1);
        hashMap.put("ujn", 2);
        hashMap.put("word", 4);

        /*hashMap.forEach(new BiConsumer<String, Integer>() {
            @Override
            public void accept(String s, Integer integer) {
                System.out.println("key: " + s + " val: " + integer);
            }
        });*/

        hashMap.forEach((key, val) -> System.out.println("key: " + key + " val: " + val));
    }

    public static void main9(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("abcd");
        list.add("zko");
        list.add("ujn");
        list.add("hello");

        list.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });

        System.out.println("=============");

        list.forEach(s -> System.out.println(s));

        System.out.println("=====排序=========");

      /*  list.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);
            }
        });*/

        list.sort((o1, o2) -> o1.compareTo(o2));
        list.forEach(s -> System.out.println(s));
    }

    public static void main8(String[] args) {
        int count = 10;
        MoreParameterNoReturn moreParameterNoReturn = (int a, int b) -> {
            System.out.println(count);
            //count = 5;不能修改count
            System.out.println(a + b);
        };

        //count = 99;不能修改
        moreParameterNoReturn.test(1, 2);
    }

    public static void main7(String[] args) {
        int a = 1;
        int b = 2;
       /* PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1.compareTo(o2);
            }
        });*/

        PriorityQueue<Integer> priorityQueue2 = new PriorityQueue<>((o1, o2) -> o1.compareTo(o2));
        priorityQueue2.offer(a);
        priorityQueue2.offer(b);

    }

    public static void main6(String[] args) {
       // MoreParameterReturn moreParameterReturn = (int a, int b) -> {return a * b;};
        MoreParameterReturn moreParameterReturn = (a, b) -> a * b;
        System.out.println(moreParameterReturn.test(10, 20));
    }

    public static void main5(String[] args) {
        //OneParameterReturn oneParameterReturn = (a) -> {return a + 4;};
        OneParameterReturn oneParameterReturn = a -> a + 3;
        System.out.println(oneParameterReturn.test(10));

    }

    public static void main4(String[] args) {
       // NoParameterReturn noParameterReturn = () -> {return 10;};
        NoParameterReturn noParameterReturn = () -> 10;
        System.out.println(noParameterReturn.test());
    }

    public static void main3(String[] args) {
       // MoreParameterNoReturn moreParameterNoReturn = (int a, int b) -> {System.out.println(a + b);};
        //简写
        MoreParameterNoReturn moreParameterNoReturn = (a, b) -> System.out.println(a + b);
        moreParameterNoReturn.test(10, 30);
    }

    public static void main2(String[] args) {
        //OneParameterNoReturn oneParameterNoReturn = (int a) -> {System.out.println(a);};
        //简写
        OneParameterNoReturn oneParameterNoReturn = a -> System.out.println(a);
        oneParameterNoReturn.test(10);

    }

    public static void main1(String[] args) {
        NoParameterNoReturn noParameterNoReturn = new NoParameterNoReturn() {
            @Override
            public void test() {
                System.out.println("重写了test方法");
            }
        };

        noParameterNoReturn.test();
        System.out.println("===============");

        //lambda表达式
        NoParameterNoReturn noParameterNoReturn2 = () -> System.out.println("重写了test方法");
        noParameterNoReturn2.test();
    }
}
